﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;

namespace DataAdapter与DataSet的使用
{
    public partial class _Basic : Page
    {
        private readonly DataSet dataSet = new DataSet();
        private SqlDataAdapter dataAdapter = new SqlDataAdapter();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GetData();
            }
        }

        public void GetData()
        {
            using (var connection =
                new SqlConnection("data source=10.22.149.99;database=School;uid=Student;pwd=123456"))
            {
                string selectCommandText = "SELECT * FROM Student";

                dataAdapter = new SqlDataAdapter(selectCommandText, connection);

                dataAdapter.Fill(dataSet, "Student");
                gridview1.DataSource = dataSet.Tables["student"];
                gridview1.DataBind();
            }
        }
    }
}